'use strict';

const Controller = require('egg').Controller;

class QuestionController extends Controller {
    /* 问答及子页面 -------------------------------------------------------------- */
    async answer(){
        const { initInterestData,typeToTimeStamp } = require('../utils/index');
        const page = this.ctx.query.page || 1;
        const parentId = this.ctx.query.parentId||'';
        const categoryId = this.ctx.query.categoryId || parentId || '';
        const orderByField = this.ctx.query.orderByField || 'default';
        const beginDateTime = this.ctx.query.beginDateTime || '';
        const category = await this.ctx.service.mainCategory.mainCategory();
        const categoryResult = initInterestData(category);
        const type = this.ctx.query.type;
        var memberList = await this.ctx.service.banner.bannerList('vip_area');
        var questionList = await this.ctx.service.answer.questionList(page,15,categoryId,orderByField,typeToTimeStamp(beginDateTime));

        var data = {
            memberList:memberList,
            category:categoryResult,
            questionList:questionList,
            categoryId:categoryId,
            parentId:parentId,
            orderByField:orderByField,
            type: type || 'hot',
            beginDateTime:beginDateTime,
        };
        await this.ctx.render('page/answer/answer.html',{data:data});
    }



    async answer_daren(){
        let data ={
            navIndex:1
        };

        await this.ctx.render('page/answer/answer_daren.html', data);
    }

    async answer_darenList(){
        let data ={
            navIndex:1
        };

        await this.ctx.render('page/answer/answer_darenList.html', data);
    }


    async answer_content(){
        const id = this.ctx.params.id || this.ctx.query.id ||'';
        var content = await this.ctx.service.answer.questionContent(id);
        var result =  false;
        if(content&&content.mutualQuestion ){
            result = content.mutualQuestion;
        }
        await this.ctx.render('page/answer/answer_content.html',{data:result});
    }

}

module.exports = QuestionController;






